import Vue from "vue";
import {request} from "../../../util/request"
import "../../../common/common.less";
import dialog from "../../../util/dialog.js";

new Vue({
    el:"#louie",
    data:{
        use_balance:1,
        currency_name:"积分",
        sign_keyword:"",
        show_help:0,
        help:"",
        give:"1,10",
        sub:"0"
    },
    computed:{
        data:function(){
            let data = {
                use_balance:this.use_balance,
                currency_name:this.currency_name,
                sign_keyword:this.sign_keyword,
                show_help:this.show_help,
                help:this.help,
                give:this.give,
                sub:this.sub
            }
            return data;
        }
    },
    created:function(){
        this.get();
    },
    methods:{
        /**
         * 获取参数
         */
        get(){
            request("setting/find",{
                return:["use_balance","currency_name","give","sub","sign_keyword","show_help","help"]
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        let data = res.data.data;
                        this.use_balance = data.use_balance;
                        this.show_help = data.show_help;
                        this.help = data.help;
                        if(data.currency_name) this.currency_name = data.currency_name;
                        if(data.give) this.give = data.give;
                        if(data.sub) this.sub = data.sub;
                        if(data.sign_keyword) this.sign_keyword = data.sign_keyword;
                    }
                });
        },
        /**
         * 设置参数
         */
        submit(){
            request("setting/set",{
                data:this.data
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        dialog.alert(this,"设置成功");
                    }else{
                        dialog.alert(this,"设置失败");
                    }
                });
        }
    }
});